<?
require 'global.php';

function encodeUTF8(&$val){
	$val = utf8_encode($val);
}

$code=''; if (isset($_GET["code"])) $code = clean($_GET["code"]);

$tem=$coupon->get_row($code,'code');
$ok=1;
if(is_null($tem)){
	$ok=0;
}
else {
	if($tem['expire_date']<date('Y-m-d')) $ok=0;
	if($tem['is_used']) $ok=0;
}

// 封装
if($ok==0){
	$data=array(
		'ok'=>0,
	);
}
else {
	if($tem['discount_type']==2) {
		$tem['discount_value']=round($tem['discount_value']*$currency_rate,2);
		$tem['discount_tip']=$currency_sign.$tem['discount_value'];
	}
	else $tem['discount_tip']=(int)$tem['discount_value'].'%';
	$data=array(
		'ok'=>1,
		'discount_type'=>$tem['discount_type'],
		'discount_value'=>$tem['discount_value'],
		'discount_tip'=>$tem['discount_tip']
	);
}
//array_walk_recursive($data, 'encodeUTF8');

echo json_encode($data);